package org.mtmi.ui.controls.edits;

import java.util.Collection;

import org.mtmi.ui.IMG;
import org.mtmi.ui.actions.RetargetableAction;
import org.mtmi.ui.controls.Knob;
import org.mtmi.ui.drawables.IDrawable;

/**
 * Action to change Knob value color.
 */
public class KnobTypeAction extends RetargetableAction
{

	public KnobTypeAction() {
		super( PUSH );
	}

	@Override
	public boolean isTargetHandled(Object c) {
		return isInstanceOfOrCollectionOfInstanceOf( c, Knob.class );
	}

	@Override
	public IDrawable getImage() {
		return IMG.GetD( IMG.I_KNOB_TYPE );
	}

	@Override
	public boolean isEnabled() {
		return target!=null;
	}
	
	@Override
	public void run() {
		Object t = getTarget();
		if( t instanceof Knob ) {
			run( (Knob)t );
		} else {
			for( Object o : (Collection<?>)t ) {
				run( (Knob)o );
			}
		}
	}
	
	private void run( Knob k ) {
		k.setProgressive( !k.isProgressive() );
		k.redraw();
	}

}
